package view;

import java.awt.*;
import javax.swing.*;

/**
 * Klasse MemberCellRenderer
 * 
 * @author Magnus Brieler
 */
public class MemberCellRenderer implements ListCellRenderer {

	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {
		model.Member member = (model.Member)value;
		
		JPanel panel = new JPanel(new BorderLayout());
		JLabel name = new JLabel();
		name.setText(member.getUser().getUserName());
		JLabel position = new JLabel();
		position.setText(member.getChatroom().getCreator().equals(member.getUser()) ? "Ersteller" : (member.getChatroom().getAdmins().contains(member.getUser()) ? "Admin" : "Mitglied"));
		panel.add(name, BorderLayout.CENTER);
		panel.add(position, BorderLayout.EAST);
		
		if (cellHasFocus || isSelected) {
			panel.setBackground(Color.LIGHT_GRAY);
			name.setForeground(Color.BLACK);
			position.setForeground(Color.BLACK);
		} else {
			panel.setBackground(Color.WHITE);
			name.setForeground(Color.BLACK);
			position.setForeground(Color.BLACK);
		}
		
		return panel;
	}
	
}